﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace Sanctuary.Core.Animation
{
    public static class FrameworkExtensions
    {
        public static void Fade(this FrameworkElement element, double opacity)
        {
            new OpacityAnimation(opacity).Apply(element);
        }

        public static void FadeOut(this FrameworkElement element)
        {
            element.Fade(0.0);
        }

        public static void FadeIn(this FrameworkElement element)
        {
            element.Fade(1.0);
        }

        public static void FadeIn(this FrameworkElement element, double opacity)
        {
            element.Fade(opacity);
        }

        public static void CrossFade(this FrameworkElement elementToFadeOut, FrameworkElement elementToFadeIn)
        {
            FadeOut(elementToFadeOut);
            FadeIn(elementToFadeIn);
        }

        public static void EnterFromLeft(this FrameworkElement element, double distance)
        {
            new PanAnimation(PanType.RightToLeft, distance).Apply(element);
        }

        public static void EnterFromRight(this FrameworkElement element, double distance)
        {
            new PanAnimation(PanType.LeftToRight, distance).Apply(element);
        }

        public static void DelayInvoke(this Dispatcher dispatcher, TimeSpan time, Action action)
        {
            DispatcherTimer delayTimer = new DispatcherTimer();
            delayTimer.Interval = time;
            delayTimer.Tick += (s, e) =>
            {
                delayTimer.Stop();
                action();
            };
            delayTimer.Start();
        }
    }
}
